﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Treely.Data.Model.Abstract
{
    public abstract class AuditObject
    {
        public DateTime Created { get; set; }

        [ForeignKey("CreatedBy")]
        public string CreatedById { get; set; }

        public virtual ApplicationUser CreatedBy { get; set; }

        public DateTime? Modified { get; set; }

        [ForeignKey("ModifiedBy")]
        public string ModifiedById { get; set; }

        public virtual ApplicationUser ModifiedBy { get; set; }

        public bool Deleted { get; set; }

        public DateTime? DeletionDate { get; set; }

        [ForeignKey("DeletedBy")]
        public string DeletedById { get; set; }

        public virtual ApplicationUser DeletedBy { get; set; }

        protected AuditObject(string creatingUserId)
        {
            Created = DateTime.Now;
            CreatedById = creatingUserId;
        }

        protected AuditObject(ApplicationUser creatingUser)
        {
            Created = DateTime.Now;
            CreatedById = creatingUser.Id;
        }

        protected AuditObject()
        {
            Created = DateTime.Now;
        }

        public void Delete(string deletingUserId)
        {
            Deleted = true;
            DeletionDate = DateTime.Now;
            DeletedById = deletingUserId;
        }
    }
}